package com.yang.utils;

public class NumberUtil {
	/**
	 * 最大二次幂
	 */
	public static final int MAXIMUM_CAPACITY = 1 << 30;

	/**
	 * 大于该字数的最小二次幂
	 * 
	 * @param cap
	 * @return
	 */
	public static int tableSizeFor(Integer cap) {
		if (cap == null) {
			return 1;
		}
		int n = cap - 1;
		n |= n >>> 1;
		n |= n >>> 2;
		n |= n >>> 4;
		n |= n >>> 8;
		n |= n >>> 16;
		return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
	}

}
